//
// Mouse Gesture Recognizer
// (c) Robert Hahn / HTW Dresden
//
// Connection.cs
// -------------
// Connection and ConnectionList classes to handle connections between 
// neurons.
//

using System;
using System.Collections;
using System.ComponentModel;


namespace CNeural
{
	/// <summary>
	/// Represents a list of connections.
	/// </summary>
	[Serializable]
	public class ConnectionList : ArrayList
	{
		#region Fields
		#endregion

		#region Properties
		public new Connection this[int index] 
		{
			get 
			{
				return base[index] as Connection;
			}
			set 
			{
				base[index] = value;
			}
		}
		#endregion

		#region Constructors
		public ConnectionList() 
		{
		}
		#endregion

		#region Methods
		public void Add(Connection c) 
		{
			base.Add(c);
		}
		#endregion
	}
	
	
	/// <summary>
	/// Represents a weighted connection between 2 neurons.
	/// </summary>
	[TypeConverter(typeof(ExpandableObjectConverter)), Serializable]
	public class Connection 
	{
		#region Fields
		private Neuron otherNeuron;
		private double weight;
		private double lastWeightChange;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the neuron on the other end of the connection.
		/// </summary>
		public Neuron OtherNeuron 
		{
			get { return this.otherNeuron; }
			set { this.otherNeuron = value; }
		}


		/// <summary>
		/// Gets or sets the weight of the connection.
		/// </summary>
		public double Weight 
		{
			get { return this.weight; }
			set { this.weight = value; }
		}


		/// <summary>
		/// Gets the weighted output of this connection.
		/// </summary>
		public double Output 
		{
			get { return this.otherNeuron.Output * this.Weight; }
		}


		/// <summary>
		/// Gets or sets the value of the weight change in the last learning 
		/// step.
		/// </summary>
		public double LastWeightChange 
		{
			get { return this.lastWeightChange; }
			set { this.lastWeightChange = value; }
		}
		#endregion

		#region Constructors
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="otherNeuron"></param>
		/// <param name="weight"></param>
		public Connection(Neuron otherNeuron, double weight) 
		{
			this.otherNeuron = otherNeuron;
			this.weight = weight;
		}
		#endregion
	}
}
